package com.user_hosted_storage.server.bl;

import java.util.Arrays;
import java.util.HashSet;

import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;
import javax.xml.bind.JAXBContext;

import com.sun.jersey.api.json.JSONConfiguration;
import com.sun.jersey.api.json.JSONJAXBContext;
import com.user_hosted_storage.dto.ClientDTO;
import com.user_hosted_storage.dto.CommunityDTO;
import com.user_hosted_storage.dto.CommunityMemberDTO;
import com.user_hosted_storage.dto.DTO;

@SuppressWarnings({"unchecked","rawtypes"})
@Provider
public class JAXBContextResolver implements ContextResolver<JAXBContext> {

    private JAXBContext jsonContext;
    
	private Class[] types = {ClientDTO.class,CommunityDTO.class, CommunityMemberDTO.class,DTO.class};
    
	private HashSet typesSet;
	
	 public JAXBContextResolver() throws Exception {
	    	this.typesSet = new HashSet(Arrays.asList(types));
	        this.jsonContext = new JSONJAXBContext(JSONConfiguration.natural().build(),types);
	    }

	    public JAXBContext getContext(Class<?> objectType) {
	        return (typesSet.contains(objectType)) ? jsonContext : null;
	    }
}
